/**
 * create by young (young2f@outlook.com) on 2020/9/16
 */


'use strict';
import React from 'react';
import {
  AutoComplete,
  Button,
  DatePicker,
  Form,
  Input,
  InputNumber,
  notification,
  Popconfirm,
  Select,
  Switch,
  Table
} from 'antd';

import {FormField, FormLayout, ModalFooter, ModalView, SearchForm} from 'antd-extra';
import FormBase from '../../../components/Base/FormBase';
import {connect} from "dva";
import moment from 'moment';
import 'moment/locale/zh-cn';

import ViewTitle from "../../../components/ViewTitle";
import EditableTable from '../../../components/EditableTable';
import {validate} from "@babel/core/lib/config/validation/options";
import {title} from "mockjs/src/mock/random/text";

moment.locale('zh-cn');

@Form.create()
@connect(({
            tenant,
            global,
            dynamicLabel, vendor, customer,
            dic
          }) => ({...tenant, ...dic, ...dynamicLabel, ...global, ...vendor, ...customer}))
export default class ModalCreateOrEditShippingFee extends FormBase {
  constructor(props) {
    super(props);
    this.state = {};
  }

  componentDidMount() {

  }

  renderFoot = () => {
    const {foot, value, record, callback, modalRef, form} = this.props;

    if (foot) {
      return foot(value, modalRef);
    } else {
      return (
        <ModalFooter>
          <Button type="primary" onClick={() => {
            form.validateFields((err, values) => {

              if (err) {
                const {code} = err;
                const {errors} = code;
                errors.forEach(item => {
                  notification.error(item);
                });
                return;
              }
              values.createdType = "新建";
              callback(values);
              modalRef.close();
            });

          }}>确定</Button>
          <Button onClick={() => {
            modalRef.close();
          }}>取消</Button>
        </ModalFooter>
      );
    }
  };

  render() {
    const {form,  record = {}} = this.props;
    const {code = 'SPF' + Date.now().valueOf(),name,count, deliverChannel,memo, shippingFee} = record;


    return (
      <div>
        <FormLayout form={form} cols={1}>
          <FormField
            label={'记录编码'}
            name={'code'}
            initialValue={code}
          >
            <Input disabled style={{width: '100%'}}
            >
            </Input>
          </FormField>
          <FormField
            label={'承运人名称'}
            name={'deliverChannel'}
            initialValue={deliverChannel}
            required={true}
          >
            <Input  style={{width: '100%'}}
            >
            </Input>
          </FormField>
          <FormField
            label={'商品名称'}
            name={'name'}
            initialValue={name}
          >
            <Input style={{width: '100%'}}
            >
            </Input>
          </FormField>
          <FormField
            label={'发货数量'}
            name={'count'}
            initialValue={count}
          >
            <InputNumber style={{width: '100%'}}

            >
            </InputNumber>
          </FormField>
          <FormField
            label={'运费'}
            name={'shippingFee'}
            initialValue={shippingFee}
            required={true}
          >
            <InputNumber style={{width: '100%'}}

            >
            </InputNumber>
          </FormField>
          <FormField
            label={'备注'}
            name={'memo'}
            initialValue={memo}
          >
            <Input style={{width: '100%'}}
            >
            </Input>
          </FormField>
        </FormLayout>
        {this.renderFoot()}
      </div>
    );
  }
}

